<?php


class VoucherBaseModel extends BaseModel
{
    protected $table = 'yf_voucher_base';

    protected $principal = 'voucher_id';

    /**
     * 状态
     */
    const STATE = [
        'unused' => 1,//未用
        'used' => 2,//已用
        'overdue' => 3,//过期
        'back' => 4 //收回
    ];

    public function countVaildByUser(int $user_id)
    {
        return $this->count([
            'voucher_owner_id' => $user_id,
            'voucher_state' => self::STATE['unused']
        ]);
    }
}